#include "unp.h"


int main(int argc , char *argv[])
{
   pool_t *pool;
   mqd_t mqd;
   int ret , len , pro;
 
   while( (ret = getopt(argc,argv,":l:p:")) != -1){
      switch(ret){
	 case 'l':
           len = atoi(optarg); 
           break;
         case 'p':
            pro = atoi(optarg);
           break;
         case '?':
           err_msg("invalid opt %s",argv[optind]);
           break;
         case ':':
           err_msg("invalid value %s",argv[optind]);
           break;
         default :
           err_msg("no valid options %s",argv[optind]);
           break;
      }
   }

   if(optind != (argc-1))
      err_quit("usage(%d): mq_send  -l len -p prio <name>",optind);


   mqd = mq_open(argv[optind],O_WRONLY);
   if(mqd == -1)
      err_sys("mq_open error!");

   pool = create_pool(1024); 

   char *buf = pool_calloc(pool,len);
   if(!buf)
      err_sys("pool_calloc error!");

   ret = mq_send(mqd,buf,len,pro);
   if(ret == -1)
     err_sys("mq_send error");

   destroy_pool(pool);
   mq_close(mqd);
   return 0;
}
